package LeetCode.leetcode226;




class Solution {
    public TreeNode invertTree(TreeNode root) {
        if (root == null)
            return root;
        TreeNode tmp;
        //直接交换左右子树，无论是否为null
        tmp = root.left;
        root.left = root.right;
        root.right = tmp;
        //左递归
        invertTree(root.left);
        //右递归
        invertTree(root.right);
        return root;
    }
    static void invert(TreeNode node){
        if (node == null)
            return;
        TreeNode tmp;
        //直接交换左右子树，无论是否为null
        tmp = node.left;
        node.left = node.right;
        node.right = tmp;
        //左递归
        invert(node.left);
        //右递归
        invert(node.right);
    }
}
